package com.yuyou.fn.common.util;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JWTToken {


    public static String generate(String name , Map<String,Object> payload, Date expire, String key){
        return Jwts.builder()
                .setSubject(name)
                .addClaims(payload)
                .setExpiration(expire)
                .signWith(SignatureAlgorithm.HS512, key)
                .compact();
    }

    public static Claims parse(String token , String key ){
        return Jwts.parser()
                .setSigningKey(key)
                .parseClaimsJws(token)
                .getBody();
    }

}
